package com.wisedu.wec.bank.dal.sqlDao;

import com.wisedu.wec.bank.common.enums.ErrorCode;
import com.wisedu.wec.bank.common.exception.DaoException;
import com.wisedu.wec.bank.dal.mapper.BankMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: wec-mall-bank-apps
 * @description:
 * @author: Liuzidan
 * @create: 2021-01-08 11:04
 **/
@Service
public class BankDaoImpl implements BankDao  {
    @Autowired
    BankMapper bankMapper;

    @Override
    public  int balanceIncr(String accountId, Double price) throws DaoException {
       int affectedRows=-1;
        try {
       affectedRows=    bankMapper.updateBalanceIncr(accountId, price);
        } catch (Exception e) {
            throw  new DaoException(e.getMessage(),e);
        }
        return affectedRows;
    }

    @Override
    public int balanceDecr(String accountId, Double price)  throws DaoException{
        int affectedRows=-1;
        try {
       affectedRows=     bankMapper.updateBalanceDecr(accountId, price);
        } catch (Exception e) {
            throw  new DaoException(e.getMessage(),e);
        }
        return affectedRows;
    }
}
